package com.uh.microservice.core.spring.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

/**
 * 访问请求拦截的配置
 * Created by liming on 2017/9/20.
 */
@Configuration
//public class WebMvcConfig extends WebMvcConfigurerAdapter {
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private ParamsIntercpetor paramsIntercpetor;


    /**
     * 设置session区域解析器，默认为中文
     * @return
     */
    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver slr = new SessionLocaleResolver();
        slr.setDefaultLocale(Locale.CHINA);
        return slr;
    }

    //添加拦截和过滤的请求配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(paramsIntercpetor).addPathPatterns("/**").excludePathPatterns(
                "/usr/login","/error"
        );

        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(
                "/usr/login","/error"
        );


       // super.addInterceptors(registry);
    }
}
